<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Jobprofile_model extends CI_Model
{
	
	public function __construct()
	{
		parent::__construct();

	}
	function users_getall($userid)
	{
	   
		/*$users = $this->db->get('users',$userid);
	    return $users->result();*/
	}

	function designation_getall()
	{
	    $query = $this->db->get('user_type');
	    return $query->result();
	}
	function hobbies_getall()
	{
	    $query2 = $this->db->get('hobbies');
	    return $query2->result();
	}
	function skills_insert($insert)
	{
		//print_r($insert);
		//exit;
	   $this->db->insert('skills',$insert);
	 	 //  return $this->db->insert($add);	
	}
	function skills_getall()
	{
	   	$this->db->select('skills.id,user_type.name AS titlename,skills.name AS skillname');
    	$this->db->from('user_type');
    	$this->db->join('skills','user_type_id = user_type.id');
    	$getskills = $this->db->get();
		return $getskills->result();
	}
	function efficiency_insert($insert)
	{
		//print_r($insert);
		//exit;
	    $this->db->insert('efficiency',$insert);
	 	//  return $this->db->insert($add);	
	}
	function efficiency_getall()
	{
	  
		$this->db->select('efficiency.id,user_type.name AS titlename,efficiency.name AS efficiencyname');
    	$this->db->from('user_type');
    	$this->db->join('efficiency', 'user_type_id = user_type.id');
    	$getefficiency = $this->db->get();
		return $getefficiency->result();
	}
	function tools_insert($insert)
	{
		//print_r($insert);
		//exit;
	    $this->db->insert('tools',$insert);
	 	
	}
	function tools_getall()
	{
	  
		$this->db->select('tools.id,user_type.name AS titlename,tools.name AS toolname');
    	$this->db->from('user_type');
    	$this->db->join('tools', 'user_type_id = user_type.id');
    	$gettools = $this->db->get();
		return $gettools->result();
	}
	
	public function get_efficiency_by_user_type_id($user_type_id)
	{
		//echo $user_type_id;
		//exit;
		/*$this->db->select('efficiency.*,user_type.name');
		$this->db->from('efficiency');
		$this->db->where('user_type_id',$user_type_id);
		$this->db->join('user_type', 'user_type_id = user_type.id');*/		
		$this->db->select('user_type.*,efficiency.name');
		$this->db->from('user_type');
		$this->db->where('user_type_id',$user_type_id);
		$this->db->join('efficiency', 'user_type_id = user_type.id');
	 	return $this->db->get()->result();
		}
	public function get_skills_by_user_type_id($user_type_id)
	{
		$this->db->select('user_type.*,skills.*');
		$this->db->from('user_type');
		$this->db->where('user_type_id',$user_type_id);
		$this->db->join('skills', 'user_type_id = user_type.id');
	 	return $this->db->get()->result();
		}
	public function get_tools_by_user_type_id($user_type_id)
	{
		$this->db->select('user_type.*,tools.name');
		$this->db->from('user_type');
		$this->db->where('user_type_id',$user_type_id);
		$this->db->join('tools', 'user_type_id = user_type.id');
	 	return $this->db->get()->result();
		}

	public function create_efficiency($insert)
	{
		$this->db->insert('efficiency_custom',$insert);
	}
	
	public function get_all_profilelist_by_user_id()
	{
		//return $this->db->get_where('user_type',array('id'=>@$id))->row_array();
	}
	function efficiency_custom_insert($insert)
	{
		//$this->db->insert('efficiency_custom',$insert);
		//echo '<pre>;
		foreach($insert as $efficiency)			
					{
					//print_r($insert);	
				$this->db->insert('efficiency_custom',$efficiency);
				}
				//exit;
		
	}
	
	function skill_custom_insert($insert)
	{
				foreach($insert as $skill)			
				{
				$this->db->insert('skills_custom',$skill);
				}
				//exit;
		
	}
	
	function tool_custom_insert($insert)
	{
				foreach($insert as $tool)			
				{
				$this->db->insert('tools_custom',$tool);
				}
				//exit;
		
	}
	
	function user_hobbies_insert($insert)
	{
		
				foreach($insert as $hobbies)			
				{
				$this->db->insert('user_hobbies',$hobbies);
				}
				
	}
	
	function coffeebyid($id)
	{
		$this->db->select('coffee.*');
    	$this->db->from('users');
    	$this->db->join('coffee', 'user_id = users.id');
		$this->db->where('coffee.user_id =',$id);
		$coffeebyid = $this->db->get();
		return $coffeebyid->result();
	}
	
	function skills_getall_by_id($id)
	{
	    $this->db->select('skills_custom.*,users.username AS username,skills_custom.name AS skillname');
    	$this->db->from('users');	
    	$this->db->join('skills_custom', 'user_id = users.id');
		$this->db->where('skills_custom.user_id =',$id);
    	$getskillsid = $this->db->get();
		return $getskillsid->result();
	}
	function tools_getall_by_id($id)
	{
	    $this->db->select('tools_custom.*,users.username AS username,tools_custom.name AS toolname');
    	$this->db->from('users');
    	$this->db->join('tools_custom', 'user_id = users.id');
		$this->db->where('tools_custom.user_id =',$id);
    	$gettoolsid = $this->db->get();
		return $gettoolsid->result();
	}
	function efficiency_getall_by_id($id)
	{
		
	    $this->db->select('efficiency_custom.*,users.username AS username,efficiency_custom.name AS efficiencyname');
    	$this->db->from('users');
    	$this->db->join('efficiency_custom', 'user_id = users.id');
		$this->db->where('efficiency_custom.user_id =',$id);
    	$getefficiencyid = $this->db->get();
		return $getefficiencyid->result();
	}

	function hobbies_getall_by_id($id)
	{
		$this->db->select('user_hobbies.*');
    	$this->db->from('users');
    	$this->db->join('user_hobbies', 'user_id = users.id');
		$this->db->where('user_hobbies.user_id =',$id);
		
	   
		$hobbies = $this->db->get();
	    return $hobbies->result();
	}
	
		
	function efficiencychart($id)
	{
		$this->db->select('efficiency_custom.name,efficiency_custom.level');
    	$this->db->from('users');
    	$this->db->join('efficiency_custom', 'user_id = users.id');
		$this->db->where('efficiency_custom.user_id =',$id);
		$efficiencychart = $this->db->get();
		return $efficiencychart->result();
/*
           foreach($efficiencychart as $row) { // return result as assoc array to use in calendar
            echo $row['name'];
            echo $row['level'];*/
       

      // return $efficiencychart->result();
        
	}
	
	function skillschart($id)
	{
		$this->db->select('skills_custom.name,skills_custom.level');
    	$this->db->from('users');
    	$this->db->join('skills_custom', 'user_id = users.id');
		$this->db->where('skills_custom.user_id =',$id);
		$skillschart = $this->db->get();
		return $skillschart->result();
	}
	
	function toolschart($id)
	{
		$this->db->select('tools_custom.name,tools_custom.level');
    	$this->db->from('users');
    	$this->db->join('tools_custom', 'user_id = users.id');
		$this->db->where('tools_custom.user_id =',$id);
		$toolschart = $this->db->get();
		return $toolschart->result();
	}
	
	function hobbyimage($id)
	{
		$this->db->select('user_hobbies.*,hobbies.*');
    	$this->db->from('hobbies');
    	$this->db->join('user_hobbies', 'hobbies_id = hobbies.id');
		$this->db->where('user_hobbies.user_id =',$id);
		$hobbyimage = $this->db->get();
		return $hobbyimage->result();
	}
	
	function skillsimage($id)
	{
		$this->db->select('skills_custom.*,skills.*,skills.name AS oldname,skills_custom.name AS newname');
    	$this->db->from('skills');
    	$this->db->join('skills_custom', 'skills_id = skills.id');
		$this->db->where('skills_custom.user_id =',$id);
		$skillsimage = $this->db->get();
		return $skillsimage->result();
	}
	
	function userdetails($id)
	{
		$this->db->select('users.*');
    	$this->db->from('users');
    	$this->db->where('id =',$id);
		$userdetails = $this->db->get();
		return $userdetails->result();
	}
	function designationbyid($id)
	{
		$this->db->select('users_groups.*,user_type.*');
    	$this->db->from('user_type');
    	$this->db->join('users_groups', 'user_type_id = user_type.id');
		$this->db->where('users_groups.user_id =',$id);
		$designationbyid = $this->db->get();
		return $designationbyid->result();
	}
	function efficiencyfields($id)
	{
		$this->db->select('efficiency_custom.*,');
    	$this->db->from('users');
    	$this->db->join('efficiency_custom', 'user_id = users.id');
		$this->db->where('efficiency_custom.user_id =',$id);
		$efficiencyfields = $this->db->get();
		return $efficiencyfields->result_array();
/*
           foreach($efficiencychart as $row) { // return result as assoc array to use in calendar
            echo $row['name'];
            echo $row['level'];*/
       

      // return $efficiencychart->result();
        
	}
	
	public function get_user_details($id)
	{
		$this->db->select('users.*,users_groups.*');
		$this->db->from('users');
		$this->db->where('users.id = '.$id);
		$this->db->join('users_groups','users.id = users_groups.user_id');
		return $this->db->get()->row_array();
	}
	public function edit_profile($update_values){
		$this->db->update('users',$update_values,array('id'=>$this->session->userdata('user_id')));
	}
	
	public function get_job_details()
	{
		// changing this 
		$this->db->select('users_groups.user_id,groups.name as groupname,department.name as dep_name,user_type.name as usr_name');
		$this->db->from('users_groups');		
		$this->db->join('groups','users_groups.user_id=groups.id');
		$this->db->join('department','users_groups.user_id = department.id');
		$this->db->join('user_type','users_groups.user_id = user_type.id');
		$this->db->where('user_id',$this->session->userdata('user_id'));
		//$this->db->get();
	//	echo  $this->db->last_query();
		return $this->db->get()->row_array();
	}
	
	public function do_upload($id,$file_name)
	{
	$this->db->update('users',array('profile_image'=>$file_name),array('id'=>$id));	
	}
	
	/*public function get_skills_by_user_id($user_type_id)
	{
		$this->db->select('user_type.*,skills.*');
		$this->db->from('user_type');
		$this->db->where('user_type_id',$user_type_id);
		$this->db->join('skills', 'user_type_id = user_type.id');
	 	return $this->db->get()->result();
		}*/



}
